package com.yinhai.message.client.activemq.util;

/**
 * ActiveMQ的工具类
 * @author maxp 2017年3月15日13:34:07
 */
public class AMQUtil {

   /* private static final Logger LOGGER = LoggerFactory.getLogger(AMQUtil.class);
    private static String url;
    private static String dequeue;
    private static String user;
    private static String pass;
    private static Connection connection;

    static {
        Properties properties = new Properties();
        try{
            properties.load(AMQUtil.class.getClassLoader().getResourceAsStream("TaMessage.properties"));
            url = properties.getProperty("url");
            dequeue = properties.getProperty("dequeue");
            user = properties.getProperty("user");
            pass = properties.getProperty("pass");
            connection = new ActiveMQConnectionFactory(url).createConnection();
        }catch (IOException e){
            LOGGER.error(e.getMessage());
        }catch (JMSException e){
            LOGGER.error(e.getMessage());
            connection = null;
        }
    }

    *//**
     *
     * @return
     *//*
    public static Connection  getConnection(){
        return connection;
    }

    *//**
     * 获取ActiveMQ的Session对象
     * @return
     *//*
    public static Session getAMQSession(){
        Session session = null;
        try{
            connection.start();
            session = connection.createSession(true,Session.SESSION_TRANSACTED);
        }catch (JMSException e){
            LOGGER.error(e.getMessage());
        }
        return session;
    }

    *//**
     * 发送消息到AMQ
     *//*
    public static void sendMessage(ITMMessageVo messageVo){
    	System.out.println("test-send");
        Session session = getAMQSession();
        Destination destination = null;
        MessageProducer messageProducer = null;
        try{
            destination = session.createQueue(dequeue);
            messageProducer = session.createProducer(destination);
            messageProducer.send(session.createObjectMessage(messageVo));
            session.commit();
        }catch (JMSException e){
            LOGGER.error(e.getMessage());
        }finally {
            try{
                messageProducer.close();
                session.close();
                connection.stop();
            }catch (JMSException e){
                LOGGER.error(e.getMessage());
            }
        }
    }*/

}
